<template>
  <div class="redirect">
    <keep-alive>
      <router-view class="redirect" v-if="$route.meta.keepAlive" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" />
  </div>
</template>
<script>
// layout中的router-view中的:key是作用在此处 一旦配置中key里的两个值相同就不会再走created 此组件就会被复用
// 问题1 为什么路由里面只是设置一个keepalive为true 而KEY_VALU不配置缓存参数时不管用
// 因为当路由的name值相同时 此组件才会被重用  不配置KEY_VALU的话每次进来此组件都会重新渲染 及时之前走的时候keep-alive组件内部但无法保存，所以不管用
export default {
  created() {
    this.$bus.emit('layout-router-moudle-change', this.$route.meta);
    let path = this.$route.params.path;
    let name = this.$route.params.name;
    if (path) {
      this.$router.push({ path: path });
      return;
    } else if (name) {
      let param = this.$route.params.param;
      this.$router.push({ name: name, params: param });
    }
  }
};
</script>
<style lang="scss" scoped>
.redirect {
  width: 100%;
  height: 100%;
  .router-view {
    height: calc(100% - 49px);
  }
}
</style>
